# coding:utf-8

import requests
import json


class ZhongTong:

    def __init__(self, start_pro, start_city, des_pro, des_city):
        self.data = {
            "code": 'undefined',
            "dispProv": des_pro,
            "dispCity": des_city + u'市',
            "sendProv": start_pro,
            "sendCity": start_city + u'市',
            "weight": 1,
            "_": 1500607187624
        }

        self.headers = {
            "Referer": "http://www.zto.com/GuestService/PriceQuery"
        }

    def get_price(self):
        self.data['weight'] = 1
        r = requests.get('http://www.zto.com/GuestService/GetPrice', params=self.data, headers=self.headers)
        res_first = json.loads(r.text)
        self.data['weight'] = 2
        r = requests.get('http://www.zto.com/GuestService/GetPrice', params=self.data, headers=self.headers)
        res_second = json.loads(r.text)
        first_price = int(res_first['Data']['price'])
        second_price = int(res_second['Data']['price'])
        return [first_price, second_price-first_price, res_first['Data']['hour']]


